﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * I/O Exception Event Arguments Class
 *     Provides an event arguments definition for I/O exception-related events. 
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;

namespace Adaptive.Foundation.IO.Zip
{
    /// <summary>
    /// Provides an event arguments definition for I/O exception-related events.
    /// </summary>
    public class IoExceptionEventArgs : ExceptionEventArgs
    {

        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// Value indicating whether the I/O error occured on a memory stream.
        /// </summary>
        private bool _memoryStreamError;
        /// <summary>
        /// Value indicating whether the I/O error occured on disk.
        /// </summary>
        private bool _diskError;
        #endregion

        /*--------------------------------------------------------------------------------
	 * Constructor / Dispose / Destructor Methods
	 *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public IoExceptionEventArgs()
            : base()
        {
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="exceptionCaught">
        /// The <see cref="Exception"/> that caused the event.
        /// </param>
        public IoExceptionEventArgs(Exception exceptionCaught)
            : base(exceptionCaught)
        {
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="source">
        /// A string description of the event source.
        /// </param>
        public IoExceptionEventArgs(string source)
            : base(source)
        {
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="source">
        /// A string description of the event source.
        /// </param>
        /// <param name="exceptionCaught">
        /// The <see cref="Exception"/> that caused the event.
        /// </param>
        public IoExceptionEventArgs(string source, Exception exceptionCaught)
            : base(source, exceptionCaught)
        {
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="exceptionCaught">
        /// The <see cref="Exception"/> that caused the event.
        /// </param>
        /// <param name="diskError">
        /// A value indicating whether the I/O error occured as a result of a disk-oriented operation.
        /// </param>
        public IoExceptionEventArgs(Exception exceptionCaught, bool diskError)
            : base(exceptionCaught)
        {
            _memoryStreamError = !diskError;
            _diskError = diskError;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="source">
        /// A string description of the event source.
        /// </param>
        /// <param name="diskError">
        /// A value indicating whether the I/O error occured as a result of a disk-oriented operation.
        /// </param>
        public IoExceptionEventArgs(string source, bool diskError)
            : base(source)
        {
            _memoryStreamError = !diskError;
            _diskError = diskError;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="source">
        /// A string description of the event source.
        /// </param>
        /// <param name="exceptionCaught">
        /// The <see cref="Exception"/> that caused the event.
        /// </param>
        /// <param name="diskError">
        /// A value indicating whether the I/O error occured as a result of a disk-oriented operation.
        /// </param>
        public IoExceptionEventArgs(string source, Exception exceptionCaught, bool diskError)
            : base(source, exceptionCaught)
        {
            _memoryStreamError = !(diskError);
            _diskError = diskError;
        }
        #endregion

        /*--------------------------------------------------------------------------------
	 * Public Properties
	 *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets or sets a value indicating whether the exception is a result of a disk
        /// error.
        /// </summary>
        /// <value>
        /// <b>true</b> if the exception was caught during a disk file read or write;
        /// otherwise, <b>false</b>.
        /// </value>
        public bool DiskError
        {
            get
            {
                return _diskError;
            }
            set
            {
                _diskError = value;
                _memoryStreamError = !(value);
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the exception is a result of a memory
        /// error.
        /// </summary>
        /// <value>
        /// <b>true</b> if the exception was caught during a memory read or write;
        /// otherwise, <b>false</b>.
        /// </value>
        public bool MemoryError
        {
            get
            {
                return _memoryStreamError;
            }
            set
            {
                _memoryStreamError = value;
                _diskError = !(value);
            }
        }
        #endregion
    }
}